package com.xhz;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Trace {
	private static final SimpleDateFormat dateFmort = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public static String info (String message) {
		String str = trace(message, "INFO");
		println(str, null);
		return message;
	}
	
	public static String error (String message, Throwable e) {
		String str = trace(message, "ERROE");
		println(str, e);
		return message;
	}
	
	public static String trace(String message, String level) {
		StringBuilder sb = new StringBuilder();
		sb.append(dateFmort.format(Calendar.getInstance().getTime()));
		sb.append(' ').append(level).append(' ');
		sb.append('<').append(Thread.currentThread().getName()).append('>');
		sb.append(' ').append(message);
		return sb.toString();
	}
	
	private static void println(String str, Throwable e) {
		System.err.println(str);
		if (null != e)
			e.printStackTrace(System.out);
	}
}
